package com.blockchain.console.servlets.user;

import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.console.service.user.UserManage;
import com.blockchain.console.service.user.entity.User;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.IntegerParser;


public class Open extends AbstractUserServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void processGet(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		processPost(request, response, serviceSession);
	}
	
	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		int type = IntegerParser.parse(request.getParameter("type"));
		UserManage userManage = serviceSession.getService(UserManage.class);
		User user = userManage.getSfz(id);
		response.setContentType(user.name);
		OutputStream out = response.getOutputStream();
		if (type == 1) {//1:正面照。2：反面照。
			out.write(user.sc_zmz.getBytes(Long.parseLong("1"), (int) user.sc_zmz.length()));
		}
		if (type == 2) {
			out.write(user.sc_fmz.getBytes(Long.parseLong("1"), (int) user.sc_fmz.length()));
		}
	}

}
